using System;

namespace Abide_Halo_Library.Halo_2_Map
{
    public class IndexEntry : MarshalByRefObject
    {
        public String FileName
        {
            get { return tagName; }
            internal set { tagName = value; }
        }
        public String Class
        {
            get { return new string(tag).Trim(); }
            internal set { tag = value.ToCharArray(); }
        }
        public Int32 Offset
        {
            get { return offset; }
            internal set { offset = value; }
        }
        public Int32 VirtualOffset
        {
            get { return virtualOffset; }
            internal set { virtualOffset = value; }
        }
        public Int32 Ident
        {
            get { return id; }
            internal set { id = value; }
        }
        public Int32 Size
        {
            get { return size; }
            internal set { size = value; }
        }
        public Int32 Magic
        {
            get { return magic; }
            internal set { magic = value; }
        }

        String tagName;
        Char[] tag;
        Int32 id;
        Int32 virtualOffset;
        Int32 size;
        Int32 offset;
        Int32 magic;

        internal IndexEntry() { }
        public IndexEntry(OBJECT_ENTRY objEntry, Int32 secondaryMagic, String fileName)
        {
            tagName = fileName;
            tag = new char[] { objEntry.tag[3], objEntry.tag[2], objEntry.tag[1], objEntry.tag[0] };
            virtualOffset = objEntry.offset;
            offset = objEntry.offset - secondaryMagic;
            id = objEntry.id;
            size = objEntry.metaLength;
        }
        public static IndexEntry Create(string tagName, char[] tag, int id, int offset, int magic, int size)
        {
            return new IndexEntry
            {
                tagName = tagName,
                tag = tag,
                id = id,
                offset = offset,
                magic = magic,
                size = size,
                virtualOffset = offset + magic
            };
        }
    }
}

